<?php

include_once "basePage.php";

class fb_access extends basePage{
	
	public function fbwallposting(){
		
		require("facebook/facebook.php");
		
		$app_id ='349028765160881';
		$app_secret = "143817d77e6046650991913ea19d051d";
		
		// Init facebook api.
		$facebook = new Facebook(array(
		'appId' => $app_id,
		'secret' => $app_secret,
		'cookie' => true
		));

		// Get the url to redirect for login to facebook
		// and request permission to write on the user's wall.
		$loginUrl = $facebook->getLoginUrl(array(
    	'canvas' => 1,
    	'fbconnect' => 0,
   		'scope' => 'offline_access,publish_stream'
		));
		
		
		$user = $facebook->getUser();
		if($user){
    		echo $facebook->getAccessToken();
		}
		
		
		//create message with token gained before
		$post =  array(
    	'access_token' => 'TOKEN HERE',
    	'message' => 'This message is posted with access token - ' . date('Y-m-d H:i:s')
		);

		//and make the request
		$res = $facebook->api('/me/feed', 'POST', $post);

		//For example this can also be used to gain user data
		//and this time only token is needed
		$token =  array(
    	'access_token' => 'TOKEN HERE'
		);
		$userdata = $facebook->api('/me', 'GET', $token);
		
		/*
		// If not authenticated, redirect to the facebook login dialog.
		// The $login_url will take care of redirecting back to us
		// after successful login.
		if (! $facebook->getUser()) {
			echo <<< EOT
<script type="text/javascript">
top.location.href = "$login_url";
</script>;
EOT;
		//exit;
		}

		// Do the wall post.
		$facebook->api("/me/feed", "post", array(
		message => "I made a contribution to ",
		picture => "YOUR_PICTURE_URL",
		link => "YOUR_LINK",
		name => "YOUR_LINK_NAME",
		caption => "YOUR_CAPTION"
		));
		*/
		
	}
	
}


$page = new fb_access();
$page->header();
$page->top_menu_donor();
$page->fbwallposting();
$page->footer();
?>
